package com.example.service.provider.controller;

import com.example.service.common.api.Service1;
import com.example.service.common.api.entity.ResponseResult;
import com.example.service.common.dto.FileTestDto;
import com.example.service.common.dto.TestDto;
import com.example.service.common.vo.TestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Response;
import java.time.LocalDate;

@RestController("feignController")
@RequestMapping("/feign")
public class FeignController {

    /**
     * FeignClient假客户端
     */
    @Autowired
    private Service1 service1;

    @GetMapping("/post/pathAndBodyArg/hystrix")
    public ResponseResult<TestVo> pathAndBodyArgPostHystrix(){
        return service1.pathAndBodyArgPostHystrix("pathArg",TestDto.defaultCreate());
    }


    @GetMapping("/get/noArg/hystrix")
    public ResponseResult<TestVo> noArgGetHystrix(){
        //熔断出现
        for(int i=0;i<5;i++){
            System.out.println(service1.noArgGetHystrix());
        }
        return service1.noArgGetHystrix();
    }



    @GetMapping("/get/noArg")
    public ResponseResult<TestVo> noArgGet(){
        return service1.noArgGet();
    }


    @GetMapping("/get/pathArg")
    public ResponseResult<TestVo> pathArgGet(){
        return service1.pathArgGet("pathArg",LocalDate.now());
    }

    @GetMapping("/post/pathAndBodyArg")
    public ResponseResult<TestVo> rpcPathAndBodyArgPost(){
        return service1.pathAndBodyArgPost("pathArg", LocalDate.now(), TestDto.defaultCreate().setAge(1616L));
    }

    /**
     * 不支持文件上传
     */
    @PostMapping("/post/file")
    public ResponseResult<TestVo> pathAndBodyArgAndFileArgPost(FileTestDto fileTestDto){
            return service1.pathAndBodyArgAndFileArgPost("元素e",fileTestDto);
    }
}
